#!/usr/bin/env python
# -*- coding: utf-8 -*-
from typing import TypeVar, List

from requests import Session

from app.models import User
from pydantic import BaseModel

from app.dao.base_dao import BaseDao
from app.db.base_class import Base
from app.models.constant import Constant
from app.models.strategy import Strategy
from app.models.user_setting import UserSetting


class StrategyDao(BaseDao[Strategy]):
    def __init__(self):
        super(StrategyDao, self).__init__()
        self.modelClass = Strategy
        self.id = Strategy.id

    def selectByKeywords(self, db: Session, userId, keywords):
        result = db.query(User.realName, User.avatar, Strategy.userId, Strategy.name, Strategy.description, Strategy.id,
                          Strategy.createdDate, Strategy.updatedDate) \
            .filter(User.id == Strategy.userId,
                    Strategy.userId == userId,
                    Strategy.level == 3,
                    Strategy.name.like('%' + keywords + '%')).all()
        return result

    def selectItemById(self, db: Session, id):
        result = db.query(User.realName, User.avatar, Strategy.userId, Strategy.name, Strategy.description, Strategy.id,
                          Strategy.createdDate, Strategy.updatedDate) \
            .filter(User.id == Strategy.userId,
                    Strategy.id ==id).all()
        return result


strategyDao = StrategyDao()
